package com.app.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.R;
import com.app.activity.ActivityInvite;
import com.app.activity.ActivityInviteFace;
import com.app.activity.ActivityInvitecode;
import com.app.activity.ActivityInvitecodeMine;
import com.app.view.MenuPopWindow;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/1/16.
 */

public class MenuShareAdapter extends RecyclerView.Adapter {

    private Context mContext;

    private MenuPopWindow mPopWindow;

    private int[] iconRes = new int[] {
            R.mipmap.icon_invite,
            R.mipmap.icon_invite_code,
            R.mipmap.icon_invite_code_mine,
            R.mipmap.icon_scan
    };

    private String[] titles = new String[] {
        "分享有礼",
        "输入邀请码",
        "我的邀请码",
        "面对面邀请"
    };

    public MenuShareAdapter(Context context, MenuPopWindow popWindow) {
        mContext = context;
        mPopWindow = popWindow;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext).inflate(R.layout.menu_share_item_layout, parent, false);
        MViewHolder viewHolder = new MViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        MViewHolder viewHolder = (MViewHolder) holder;
        viewHolder.ivMenuIcon.setImageResource(iconRes[position]);
        viewHolder.tvMenuTitle.setText(titles[position]);

        switch (position) {
            case 0:
                viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopWindow.dismiss();
                        mContext.startActivity(new Intent(mContext, ActivityInvite.class));
                    }
                });
                break;
            case 1:
                viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopWindow.dismiss();
                        mContext.startActivity(new Intent(mContext, ActivityInvitecode.class));
                    }
                });
                break;
            case 2:
                viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopWindow.dismiss();
                        mContext.startActivity(new Intent(mContext, ActivityInvitecodeMine.class));
                    }
                });
                break;
            case 3:
                viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopWindow.dismiss();
                        mContext.startActivity(new Intent(mContext, ActivityInviteFace.class));
                    }
                });
                break;
            default:
                viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopWindow.dismiss();
                    }
                });
                break;
        }
    }

    @Override
    public int getItemCount() {
        return titles.length;
    }

    class MViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.ivMenuIcon)
        ImageView ivMenuIcon;
        @BindView(R.id.tvMenuTitle)
        TextView tvMenuTitle;



        public MViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
